userSchema.methods.checkForCanPost   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 8
rs 9.4285
nop 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 3 1
1
import mongoose from 'mongoose'
2
3
const Schema = mongoose.Schema
4
5
const userSchema = new Schema({
6
	name: {
7
		type: String,
8
		required: true
9
	},
10
	location: {
11
		type: String
12
	},
13
	isAdmin: {
14
		type: Boolean
15
	},
16
	canPost: {
17
		type: Boolean,
18
		validate: function(v) {
19
			return v === true && this.isAdmin === true
20
		}
21
	}
22
})
23
24
userSchema.methods.checkForCanPost = function(cb) {
25
	this.model('User').findOne({
26
		name: this.name,
27
		canPost: true
28
	}, function(err, val) {
29
		cb(!!val)
30
	})
31
}
32
33
34
const User = mongoose.model('User', userSchema)
35
36
export default User